from flask import Flask
from flask import request
import os
import sys
from test_lgb import load_lgbs, prediction
from flask_cors import CORS

app = Flask(__name__)

interface_path = os.path.dirname(__file__)
sys.path.insert(0, interface_path)  # 将当前文件的父目录加入临时系统变量
gbm_dict = load_lgbs('.\\model\\')
CORS(app, supports_credentials=True)


@app.route('/predict', methods=['POST'])
def hello_world():
    data = request.form.to_dict()
    print(data)
    Daytime = int(data['Daytime'][:-1])
    temp = int(data['tem'])
    WD = data['WD']
    WS = data['WS']
    RH = data['RH']
    response = prediction(Daytime, temp, WD, WS, RH, gbm_dict)
    print(response)
    return response


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=23353)
